package com.bitejiuyeke.job_publish.controller;

import com.bitejiuyeke.job_publish.common.AppResult;
import com.bitejiuyeke.job_publish.exception.ApplicationException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Api → @Tag
 * @ApiIgnore → @Parameter(hidden = true) or @Operation(hidden = true) or @Hidden
 * @ApiImplicitParam → @Parameter
 * @ApiImplicitParams → @Parameters
 * @ApiModel → @Schema
 * @ApiModelProperty(hidden = true) → @Schema(accessMode = READ_ONLY)
 * @ApiModelProperty → @Schema
 * @ApiOperation(value = "foo", notes = "bar") → @Operation(summary = "foo", description = "bar")
 * @ApiParam → @Parameter
 * @ApiResponse(code = 404, message = "foo") → @ApiResponse(responseCode = "404", description = "foo")
 *
 * @Author 比特就业课
 */
// 指定测试根路径映射地址前缀
@Tag(name = "测试", description = "这是对Controller的详细描述")
// 校验
@Validated
// 映射路径
@RequestMapping("/test")
// Controller注解，返回的对象用JSON形式表示
@RestController
public class TestController {

    @Operation(summary = "环境测试方法", description = "这是对API的一个详细描述")
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring Boot...";
    }

    @Operation(summary = "主动抛出异常", description = "抛出一个Exception类型的异常")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是一个Exception");
    }

    @Operation(summary = "主动抛出自定义异常", description = "抛出一个ApplicationException类型的异常")
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是一个自定义的ApplicationException");
    }

    @Operation(summary = "发送验证码")
    @Parameters(value = {
            @Parameter(name = "phoneNum", in = ParameterIn.QUERY, description = "电话号码"),
            @Parameter(name = "type", in = ParameterIn.QUERY, description = "验证场景"),
    })
    @PostMapping("/send_test")
    public AppResult send(@RequestParam(name = "phoneNum") @NotBlank(message = "电话号不能为空") String phoneNum,
                          @RequestParam(name = "type") @NotNull(message = "类型不能为空")
                          @Min(value = 1, message = "最小是1")
                          @Max(value = 3, message = "最大是3") Integer type) {
        System.out.println(phoneNum + ","+ type);
        return AppResult.success();
    }
}
